package com.ibm.risk.irmp.base.config.service.impl;

import com.ibm.risk.irmp.base.config.service.IConfigService;
import com.ibm.risk.irmp.base.dict.dao.BaseDictItemRepository;
import com.ibm.risk.irmp.base.dict.entity.BaseDictItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Primary
@Transactional(readOnly = true)
@CacheConfig(cacheNames = "IrmpParamDataCache")
public class ConfigServiceImpl implements IConfigService {
    @Autowired
    BaseDictItemRepository dictItemRepository;

//    @Override
//    @Cacheable(key = "'BASE_CONF:' + methodName")
//    public String getHqFinBranchCode() {
//        List<BaseDictItem> hqFins = dictItemRepository.findByGroupCode(SystemConstants.HQ_BIZ_BRANCH_CODE);
//        String hqBranchCode = hqFins.get(0).getCode();
//        return hqBranchCode;
//    }


//    @Override
//    @Cacheable(key = "'BASE_CONF:' + methodName")
//    public String getHqMngBranchCode() {
//        List<BaseDictItem> hqFins = dictItemRepository.findByGroupCode(SystemConstants.HQ_MNG_BRANCH_CODE);
//        String hqBranchCode = hqFins.get(0).getCode();
//        return hqBranchCode;
//    }

    @Override
    @Cacheable(key = "'BASE_CONF:' + methodName")
    public String getLatestDataDate() {
        List<BaseDictItem> defaultDataDates = dictItemRepository.findByGroupCodeAndIsDefault("DATA_DATE", true);
        if (defaultDataDates.isEmpty()) {
            throw new RuntimeException("没有数据日期");
        }
        return defaultDataDates.get(0).getCode();
    }

}
